package com.puris.servlet.admin;

import com.puris.service.admin.ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author Sonata
 * @data 2021/11/28 15:39
 */
public class DeleteCompetitionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");

        boolean flag = false;

        ServiceImpl service = new ServiceImpl();

        try {
            flag = service.deleteCompetition(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        if (flag) {
            req.setAttribute("success", "删除成功");
        } else {
            req.setAttribute("error", "删除失败，请认真核对编号");
        }
        req.getRequestDispatcher("jsp/admin/deleteCompetition.jsp").forward(req, resp);
    }
}
